package com.tongfusoft.deal.action;

import java.util.HashMap;
import java.util.Map;

import com.tongfusoft.contract.service.ContractService;
import com.tongfusoft.da.help.DBUtils;
import com.tongfusoft.utils.UIDGeneratorService;

public class ContractAction  extends BaseWarpAction {

	
	
	public String createTemplate () {
		
		
		return "createTemplate";
	}
	
	
	public String createTemplated () {
		
		String templateName = getParameter("templateName");
		String content = getParameter("content");
		String remark =  getParameter("remark");

		String uuid = UIDGeneratorService.getUUID();
		
		Map<String,Object> param = new HashMap<String, Object>(); 
		param.put("templateName", templateName);
		param.put("templateId",uuid);
		param.put("remark",remark);
		param.put("templateContent",content );
		DBUtils.executeInsert("/deal#TCM_CONTRACT_TEMPLATE", param);
		
//		param.clear();
//		param.put("templateId",uuid );
//		param.put("templateContent",content );
//		DBUtils.executeUpdate("/deal#TCM_CONTRACT_TEMPLATE", param);
		
		return "createTemplated";
	}
	
	
	public String updateTemplate () {
		
		return "updateTemplate";
	}
	
	public String updateTemplating () {
		
		String templateName = getParameter("templateName");
		
		Map<String,Object> result = new ContractService().get(templateName);
		
		result.put("TEMPLATE_CONTENT", clobToString(result.get("TEMPLATE_CONTENT")));
		
		getRequest().setAttribute("result", result);
		return "updateTemplating";
		
	}
	public String updateTemplated () {
		
		String templateName = getParameter("templateName");
		String content = getParameter("content");
		String remark =  getParameter("remark");

		String uuid = getParameter("id");
		
		Map<String,Object> param = new HashMap<String, Object>(); 
		param.put("templateId",uuid);
		param.put("templateName",templateName);
		param.put("remark",remark);
		param.put("templateContent",content );
		DBUtils.executeUpdate("/deal#TCM_CONTRACT_TEMPLATE", param);
		
		return "updateTemplated";
	}
	
	public static void main(String[] args) {
		System.out.println(UIDGeneratorService.getUUID());
	}
	
	
}
